<?php
/**
 * Create by Phpstorm
 * User: Peco
 * Date: 2019/12/14
 * Time: 17:42
 */

namespace App\Http\Transformers\Sms;

use App\Models\SmsSetting;
use League\Fractal\TransformerAbstract;

class GetSettingSmsDetailTransformer extends TransformerAbstract
{
    public function transform(SmsSetting $smsSetting)
    {
        $data = $smsSetting->toArray();

        $configList = [];
        $value = \GuzzleHttp\json_decode($data['value'], true);
        foreach ($value as $datum){
            $key = array_key_first($datum);
            $configList[] = ['configKey'=>$key, 'configValue'=>$datum[$key]];
        }
        unset($data['value']);

        data_set($data, 'configList', $configList);

        return $data;
    }
}
